package com.weareint.common.utils;

import com.alibaba.fastjson.JSON;
import com.weareint.common.entity.LoginUser;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 *
 *
 * <pre>
 * 用户工具类
 * </pre>
 *
 * @author zzp
 * @date 2021-07-20 8:42
 */
public class UserUtils {

    /**
     *
     *
     * <pre>
     * 获取当前登录用户信息
     * </pre>
     *
     * @author: zzp
     * @param: []
     * @return com.weareint.common.entity.LoginUser
     */
    public static LoginUser getLoginUserInfo() {
        ServletRequestAttributes servletRequestAttributes =
                (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        String jsonStr = request.getHeader("loginUserInfo");
        return jsonStr == null ? null : JSON.parseObject(jsonStr, LoginUser.class);
    }
}
